﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using static AttributeSample.AttributeUsageTest;

namespace AttributeSample
{
    class Program
    {

        private static readonly StringBuilder outputText = new StringBuilder(1000);
        private static int intTes = 6666666;

        static void Main(string[] args)
        {
            //Console.WriteLine("Hello World!");
            Assembly assembly = Assembly.Load(new AssemblyName("AttributeSample:"));
            Attribute attributeTest = assembly.GetCustomAttribute(typeof(AttributeSampleTest));
            AddToOupet($"Assembly:{assembly.FullName}");

            if (attributeTest == null)
            {
                AddToOupet("AAAAAAAAAAAAA:");
                return;
            }
            else
            {
                AddToOupet("BBBBBBBBBBBB:");
            }

            foreach (Type definedType in assembly.ExportedTypes)
            {

            }


        }

        static void AddToOupet(string text) => outputText.Append($"{Environment.NewLine}{text}");

        private static void DisplayTypeInfo(Type type)
        {
            if (!type.GetTypeInfo().IsClass)
            {
                return;
            }

            AddToOupet($"{Environment.NewLine} class {type.Name}");

            IEnumerable<AttributeUsageTest> attributeUsageTest = type.GetTypeInfo().GetCustomAttributes().OfType<AttributeUsageTest>()
                .Where(a => a.Number >= intTes).ToArray();

            if (attributeUsageTest.Count() == 0)
            {
                AddToOupet("11111111111111");
            }

            else
            {
                foreach (AttributeUsageTest attribute in attributeUsageTest)
                {
                    WriteAttributeInfo(attribute);
                }
            }

            AddToOupet("改变：");


            foreach (MethodInfo method in type.GetTypeInfo().DeclaredMethods.OfType<MethodInfo>())
            {

                //IEnumerable<AttributeUsageTest> attributeToMethod = method.GetCustomAttributes();

            }

        }
        private static void WriteAttributeInfo(Attribute attribute)
        {

            if (attribute is AttributeUsageTest attributeUsageTest)
            {
                AddToOupet($"\t MOdified ：{attributeUsageTest.Number} ：{attributeUsageTest.Title}");
                if (attributeUsageTest.Issues != null)
                {
                    AddToOupet($"\t OutStand：{attributeUsageTest.Issues}");
                }
            }

        }

    }
}
